package com.syn.synold4s.control;

import android.content.Context;
import android.content.res.TypedArray;
import android.graphics.drawable.Drawable;
import android.util.AttributeSet;
import android.view.LayoutInflater;

import androidx.core.content.ContextCompat;

import com.gaoyi.basemodule.baseControl.BaseView;
import com.syn.synold4s.R;
import com.syn.synold4s.databinding.AiViewBinding;

public class AiView extends BaseView<AiViewBinding> {


    public AiView(Context context, AttributeSet attrs) {
        super(context, attrs);
    }

    @Override
    protected void initView(TypedArray ta) {
        String title = ta.getString(R.styleable.AiView_ai_title_text);
        int bgId = ta.getResourceId(R.styleable.AiView_ai_iv_src, R.drawable.ai_in);
        mBinding.tvAiTitle.setText(title);
        Drawable drawable = ContextCompat.getDrawable(mContext, bgId);
        if (drawable != null) {
            drawable.setBounds(0, 0, drawable.getIntrinsicWidth(), drawable.getIntrinsicHeight());
            mBinding.tvAiTitle.setCompoundDrawablesRelative(null, drawable, null, null);
        }
    }

    public void setNum(int num) {
        mBinding.tvAiNum.setText(String.valueOf(num));
    }

    @Override
    protected AiViewBinding getViewBinding() {
        return AiViewBinding.inflate(LayoutInflater.from(mContext));
    }

    @Override
    protected int[] getAttrs() {
        return R.styleable.AiView;
    }
}
